package com.example.chcrm.entity.common;

import lombok.experimental.Accessors;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author 邹
 * @Date 2025/4/30 20:06
 * @Version 1.0
 */
@Accessors
public class MenuTreeUtil {
    public static Map<String,Object> mapArray = new LinkedHashMap<String, Object>();
    public List<MenuVo> menuCommon;
    public List<Object> list = new ArrayList<Object>();

    public static void main(String[] args) {
        for(int i=0;i<10;i++){
            System.out.println(RandomHelper.uuid());
        }
    }

    public List<Object> menuList(List<MenuVo> menu){
        this.menuCommon = menu;
        if(menu==null){
            return list;
        }
        for (MenuVo x : menu) {
            Map<String,Object> mapArr = new LinkedHashMap<String, Object>();
            if(x.getId()== "pc" || "pc".equals(x.getId())){
                mapArr.put("menuId", x.getMenuId());
                mapArr.put("id", x.getId());
                mapArr.put("title", x.getTitle());
                mapArr.put("pid", x.getPid());
                mapArr.put("type", x.getType());
                mapArr.put("cen", x.getCen());
                mapArr.put("childList", menuChild(x.getId()));

                list.add(mapArr);
            }
        }
        return list;
    }

    public List<?> menuChild(String id){
        List<Object> lists = new ArrayList<Object>();
        //List<Map<String,String>> createList = new ArrayList<Map<String,String>>();
        //List<Map<String,String>> updateList = new ArrayList<Map<String,String>>();
        for(MenuVo a:menuCommon){
            //Map<String,String> childMap = new HashMap<String, String>();
            Map<String,Object> childArray = new LinkedHashMap<String, Object>();
            if(a!=null && a.getPid()!=null) {
                if (a.getPid() == id || a.getPid().equals(id)) {
					/*String start = a.getTitle().substring(0, 2);
					//String end =a.getTitle().substring(2,a.getTitle().length());
					if ("创建".equals(start)) {
						childMap.put("menuId", a.getMenuId());
						childMap.put("title", a.getTitle());
						createList.add(childMap);
						continue;
					}
					if ("修改".equals(start)) {
						childMap.put("menuId", a.getMenuId());
						childMap.put("title", a.getTitle());
						updateList.add(childMap);
						continue;
					}*/
                    childArray.put("menuId", a.getMenuId());
                    childArray.put("id", a.getId());
                    childArray.put("title", a.getTitle());
                    childArray.put("pid", a.getPid());
                    childArray.put("type", a.getType());
                    childArray.put("cen", a.getCen());
                    childArray.put("childList", menuChild(a.getId()));

                    lists.add(childArray);
                }
            }
        }

        return lists;
    }

}
